# code = utf-8

def write_list_in_file(content, filename='book.txt', type='w'):
    with open(filename, type, encoding='utf-8') as f:
        for item in content:
            f.writelines(str(item))
            # f.writelines('\n')


def read_list_from_file(filename='book.txt', type='r'):
    l = []
    # for line in open(filename):
    #     l.append(dict(eval(line)))
    # return l

    with open(filename, type, encoding='utf-8') as f:
        # line = dict(eval(f.readline()))
        line = f.readline()
        while line:
            # line = dict(eval(f.readline()))
            # print(line)
            # l.append(line)
            line = f.readline()
            if not line:
                break
    return l


content = [{'姓名': '郑钧天', '年份': 2012, '性别': 'nan', '班级': '3-4', '学号': 26},
           {'姓名': '郑钧天2', '年份': 2011, '性别': 'nan', '班级': '34', '学号': 25},
           {'姓名': '高多多', '年份': 2010, '性别': 'nv', '班级': '34', '学号': 40}]
# write_list_in_file(content)
l = read_list_from_file()
for i, j in enumerate(l):
    print(i, j)


def time():
    import time
    t1 = time.time()
    n = 100000
    s = 1
    for i in range(n):
        s *= i
    time.sleep(1)
    t2 = time.time()
    print('time', t2-t1)
